{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from entity import Card, Deck"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 示例：创建牌堆，并测试各个功能\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 初始化牌堆（默认从文件加载160张牌，并洗牌）\n",
    "deck = Deck()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "从牌堆顶取出： Card(137, 诸葛连弩, ♣️, A, 装备牌)\n"
     ]
    }
   ],
   "source": [
    "# 取出牌堆顶的第一张牌\n",
    "top_card = deck.draw_top_card()\n",
    "print(\"从牌堆顶取出：\", top_card)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "从牌堆中取出的指定牌： Card(136, 诸葛连弩, ♦️, A, 装备牌)\n"
     ]
    }
   ],
   "source": [
    "# 构造一个目标牌：例如牌名为“杀”，花色为\"♦️\"，点数为\"6\"\n",
    "target = Card(0, \"诸葛连弩\", \"♦️\", \"A\", \"\")  # card_id和category在匹配时不考虑，可设为任意值\n",
    "specific_card = deck.draw_specific_card(target)\n",
    "print(\"从牌堆中取出的指定牌：\", specific_card)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "当前牌堆各花色分布：\n",
      "花色 ♣️：37张，占比 23.42%\n",
      "花色 ♠️：41张，占比 25.95%\n",
      "花色 ♦️：39张，占比 24.68%\n",
      "花色 ♥️：41张，占比 25.95%\n"
     ]
    }
   ],
   "source": [
    "# 获取当前牌堆中各花色数量及占比\n",
    "suit_dist = deck.get_suit_distribution()\n",
    "print(\"当前牌堆各花色分布：\")\n",
    "for suit, (count, ratio) in suit_dist.items():\n",
    "    print(f\"花色 {suit}：{count}张，占比 {ratio:.2%}\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "当前牌堆各点数分布：\n",
      "点数 7：12张，占比 7.59%\n",
      "点数 Q：14张，占比 8.86%\n",
      "点数 K：12张，占比 7.59%\n",
      "点数 2：14张，占比 8.86%\n",
      "点数 A：10张，占比 6.33%\n",
      "点数 4：12张，占比 7.59%\n",
      "点数 8：12张，占比 7.59%\n",
      "点数 10：12张，占比 7.59%\n",
      "点数 3：12张，占比 7.59%\n",
      "点数 5：12张，占比 7.59%\n",
      "点数 J：12张，占比 7.59%\n",
      "点数 9：12张，占比 7.59%\n",
      "点数 6：12张，占比 7.59%\n"
     ]
    }
   ],
   "source": [
    "# 获取当前牌堆中各点数数量及占比\n",
    "rank_dist = deck.get_rank_distribution()\n",
    "print(\"当前牌堆各点数分布：\")\n",
    "for rank, (count, ratio) in rank_dist.items():\n",
    "    print(f\"点数 {rank}：{count}张，占比 {ratio:.2%}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 补充12张武器牌数据（卡牌id在 136 到 147）\n",
    "weapon_data = [\n",
    "    \"136,诸葛连弩,♦️,A,装备牌\",\n",
    "    \"137,诸葛连弩,♣️,A,装备牌\",\n",
    "    \"138,青釭剑,♠️,6,装备牌\",\n",
    "    \"139,寒冰剑,♠️,2,装备牌\",\n",
    "    \"140,雌雄双股剑,♠️,2,装备牌\",\n",
    "    \"141,古锭刀,♠️,A,装备牌\",\n",
    "    \"142,青龙偃月刀,♠️,5,装备牌\",\n",
    "    \"143,丈八蛇矛,♠️,Q,装备牌\",\n",
    "    \"144,贯石斧,♦️,5,装备牌\",\n",
    "    \"145,朱雀羽扇,♦️,A,装备牌\",\n",
    "    \"146,方天画戟,♦️,Q,装备牌\",\n",
    "    \"147,麒麟弓,♥️,5,装备牌\"\n",
    "]\n",
    "\n",
    "weapon_cards = []\n",
    "for line in weapon_data:\n",
    "    data = line.strip().split(',')\n",
    "    card_id = int(data[0])\n",
    "    name = data[1]\n",
    "    suit = data[2]\n",
    "    rank = data[3]\n",
    "    category = data[4]\n",
    "    weapon_cards.append(Card(card_id, name, suit, rank, category))\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 测试玩家类"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "from entity import Player"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "玩家当前手牌： [Card(136, 诸葛连弩, ♦️, A, 装备牌), Card(137, 诸葛连弩, ♣️, A, 装备牌), Card(10, 杀, ♣️, 7, 基本牌)]\n"
     ]
    }
   ],
   "source": [
    "# 创建玩家对象\n",
    "player = Player()\n",
    "# 摸牌：加入3张牌（假设这里使用部分武器牌和其他牌）\n",
    "player.draw_cards(weapon_cards[:2])  # 摸入两张武器牌\n",
    "player.draw_cards(Card(10, \"杀\", \"♣️\", \"7\", \"基本牌\"))  # 摸入一张其他牌\n",
    "print(\"玩家当前手牌：\", player.report_hand())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "玩家出掉的牌： Card(10, 杀, ♣️, 7, 基本牌)\n",
      "出牌后手牌： [Card(136, 诸葛连弩, ♦️, A, 装备牌), Card(137, 诸葛连弩, ♣️, A, 装备牌)]\n"
     ]
    }
   ],
   "source": [
    "# 出牌：尝试出一张\"杀\", ♣️, \"7\"\n",
    "target = Card(0, \"杀\", \"♣️\", \"7\", \"\")\n",
    "played = player.play_card(target)\n",
    "print(\"玩家出掉的牌：\", played)\n",
    "print(\"出牌后手牌：\", player.report_hand())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "当前装备的武器： Card(138, 青釭剑, ♠️, 6, 装备牌)\n"
     ]
    }
   ],
   "source": [
    "# 装备武器：装备一张合法的武器牌（例如 id=138 的青釭剑）\n",
    "weapon_to_equip = weapon_cards[2]  # id为138的青釭剑\n",
    "replaced = player.equip_weapon(weapon_to_equip)\n",
    "if replaced:\n",
    "    print(\"被替换的武器：\", replaced)\n",
    "print(\"当前装备的武器：\", player.weapon)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "被替换的武器： Card(138, 青釭剑, ♠️, 6, 装备牌)\n",
      "当前装备的武器： Card(139, 寒冰剑, ♠️, 2, 装备牌)\n"
     ]
    }
   ],
   "source": [
    "weapon_to_equip = weapon_cards[3]  # id为139,寒冰剑\n",
    "replaced = player.equip_weapon(weapon_to_equip)\n",
    "if replaced:\n",
    "    print(\"被替换的武器：\", replaced)\n",
    "print(\"当前装备的武器：\", player.weapon)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "\n",
    "\n",
    "\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "charlatan",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
